<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>电商</title>
</head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/front.css">
<body id="cart_list">
	<div class="container">
		<div class="row" id="header">
			<div class="col-md-3">
				<a href="<?=site_url()?>"><img class="logo" id="logo" src="<?php echo base_url("public/img/logo.jpg")?>" /></a>
			</div>
			<div class="col-md-9">
				<img style="height:50px;" class="pull-right" src="<?=base_url('public/img/shop_step_2.jpg');?>">
			</div>
		</div>
		<br/>
		<div class="row">
			<div class="col-md-12">
				<h3>收货地址:<button id="addAddress" class="btn btn-success btn-xs pull-right" href="">添加收货地址</button></h3>
				<br/>
				<table class="table table-bordered">
				<?php foreach($address as $a){?>
					<tr>
						<td class="text-center">收件人:<?=$a->name?></td>
						<td><?= $a->address?></td>
						<td><?= $a->phone?></td>
						<td width="120" class="text-center">
							<a href="#">修改</a>
							<a href="#">删除</a>
						</td>
					</tr>
				<?php }?>	
				</table>
				<table class="table table-bordered">
					<tr>
						<th>商品</th>
						<th width="150">价格</th>
						<th width="150">数量</th>
						<th width="120">小计</th>
					</tr>
					<?php 
						$sum=0;
						foreach($data as $c){
						$product=$this->Products_model->get_one($c['product_id']);
					?>
					<tr class="t">
						<td>
							<img style="width:60px;" src="<?=base_url($product->img)?>"><a href="<?=site_url('product/detail/'.$product->id);?>"><?=$product->title?></a>
						</td>
						<td>￥<?=$product->price?></td>
						<td class="cart_num"> 
							<?=$c['num']?>
						</td>
						<td>￥<?= $p=intval($product->price)* intval($c['num'])?></td> 
						<?php $sum=$sum+$p;?> 
					</tr>
					<?php }?>
				</table>
			</div>
		</div>
	</div>
	<div class="modal fade" id="addressForm">
			  <div class="modal-dialog">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title">添加收获地址</h4>      
			      </div>
			      <div class="modal-body">
			        <form>
			        	<div class="form-group">
						    <label">收货人</label>
						    <input name="name" type="text" class="form-control" placeholder="请填写姓名...">
						</div>
						<div class="form-group">
						    <label">地址</label>
						    <textarea name="address" type="text" class="form-control" placeholder="请填写地址..."></textarea> 
						</div>
						<div class="form-group">
						    <label">手机号</label>
						    <input name="phone" type="text" class="form-control" placeholder="请输入手机号...">
						</div>
			        </form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			        <button id="addressSave" type="button" class="btn btn-primary">保存</button>
			      </div>
			    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
			</div><!-- /.modal -->
	<script type="text/javascript" src="<?php echo base_url("public/js/jquery.js")?>"></script>
	<script type="text/javascript" src="<?php echo base_url("public/js/bootstrap.min.js")?>"></script>
	<script type="text/javascript">
		$(function(){
					$('#addAddress').click(function(){
						$('#addressForm').modal('show');
					})
					$('#addressSave').click(function(){
					var name =$('#addressForm input[name="name"]').val() ;  /*取addressForm后面的input 的name*/
					var address =$('#addressForm textarea[address="address"]').val();
					var phone =$('#addressForm input[phone="phone"]').val();
					$.post("<?=site_url('shopping/addAddress')?>",{
						name:name,
						address:address,
						phone:phone
					},function(data){
						data = eval("("+data+')');
						if(data.code == 'ok'){
							location.reload();
						}
						if(data.code == 'error'){
							$('#addressForm [name="'+data.field+'"]').after('<p class="error">'+data.msg+"</p>")
						}
					})
				})
			})
		
	</script>
</body>
</html>	




